package com.woniu.coupon.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.woniu.coupon.domain.Coupon;
import com.woniu.coupon.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优惠券Controller
 *
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/coupon/tbcoupon")
@Api("优惠券管理")
public class CouponWebController extends BaseController {
    @Autowired
    private ICouponService couponService;


    @RequestMapping("/web/getCouponByApartmentIdAndCustomerId")
    public AjaxResult getCouponByApartmentIdAndCustomerId(Integer apartmentId) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String userId = request.getHeader("userId");
        int customerId = Integer.parseInt(userId);

        List<Coupon> couponList = couponService.queryCouponByApartmentIdAndCustomerId(apartmentId, customerId);
          return AjaxResult.success("ok",couponList);
    }

}
